

// 导入必要的模块
// const AL_Config_Manager = require("./AL_Config_Manager");
// const AL_Game_Storage_Manager = require("./AL_Game_Storage_Manager");
// const AL_Sound_Manager = require("./AL_Sound_Manager");
// const AL_UI_Root = require("./AL_UI_Root");
// const AL_Game_Const = require("./AL_Game_Const");
const MiniGameSdk = require("./AL_SDK_MiniGameSdk").MiniGameSdk

/**
 * SDK 工具类
 */
class AL_SDK_Utils {
    static _stageCostTime = 0;
    static video_automatic_times = 0;
    static isReShow = false;
    static currentLoc = "";
    static videoFaultCount = 0;
    static _share_time = 0;
    static _dur_share_time = 0;
    static _recing = false;
    static recShareTime = 0;
    static _canShare = true;
    static show_share_once = false;
    static _onlineTime = 0;
    static webConsole = true;
    //视频广告ID
    static vidioId = "adunit-e31fee1691314430";
    //插屏id
    static interId = "adunit-5de3861e3fb15afb";
    //bannerId
    static bannerId = "adunit-8c01d1e8eb79e356";

    //军伟的sdk使用示例
    static testMiniGameSdk() {
        // MiniGameSdk.API.createWxGameHub(0,0)
    }
    static showShareMenu() {
        MiniGameSdk.API.showShareMenu();
    }
    static loadInterAd(){
        MiniGameSdk.AdvertManager.instance.loadInterAd(AL_SDK_Utils.interId);
    }
    static showInterAd(){
        MiniGameSdk.AdvertManager.instance.showInterAd();
    }
    static loadBanner(){
        //MiniGameSdk.AdvertManager.instance.loadBanner(AL_SDK_Utils.bannerId,MiniGameSdk.EAdBannerLocation.BOTTOM);
    }
    static showBanner(){
        console.log("显示banner")
        //MiniGameSdk.AdvertManager.instance.showBanner();
    }
    static hidenBanner(){
        console.log("隐藏banner")
        MiniGameSdk.AdvertManager.instance.hideBanner();
    }
    /**
     * 上报加载时间结束
     */
    static shangbao_jiazai_shijian_jiesu() {
        console.log("----->>> record_loading_time_end");
        // const loadSceneRecord = AL_Game_Storage_Manager.default.Instance.load_scene_recode;
        // // 异常上报代码已被注释
        // AL_Game_Storage_Manager.default.Instance.baocun_jiazai_changjing_jilu();
    }

    /**
     * 上报进入关卡
     * @param {number} stage 关卡 ID
     */
    static shangbao_jinru_guanqia(stage) {
        // if (!AL_Game_Const.shifou_no_net_work) {
        //     LWGSDK.shangbao_jinru_guanqia({
        //         stage,
        //         success: () => {
        //             this._stageCostTime = Math.floor(Date.now() / 1000);
        //         },
        //         fail: (error) => {
        //             console.error("进入关卡上报异常", error);
        //         }
        //     });
        // }

    }

    /**
     * 上报结束关卡
     * @param {number} stage 关卡 ID
     * @param {number} status 关卡状态
     * @param {number} [operateTimes=0] 操作次数
     */
    static shangbao_jiesu_guanqia(stage, status, operateTimes = 0) {
        // if (this._stageCostTime > 0) {
        //     const costTime = Math.floor(Date.now() / 1000) - this._stageCostTime;

        //     if (!AL_Game_Const.shifou_no_net_work) {
        //         LWGSDK.shangbao_jiesu_guanqia({
        //             stage,
        //             status,
        //             continueTimes: 0,
        //             operateTimes,
        //             costTime,
        //             success: (res) => {
        //                 console.log("结束关卡事件上报", res);
        //             },
        //             fail: (error) => {
        //                 console.error("结束关卡事件上报异常", error);
        //             }
        //         });
        //     }
        // }
    }

    /**
     * 上报用户引导
     * @param {number} guideId 引导 ID
     */
    static shangbao_yonghu_yindao(guideId) {
        // if (AL_Game_Const.shifou_no_net_work) {
        //     this.log("====report user guide", guideId);
        // } else {
        //     LWGSDK.shangbao_yonghu_yindao({
        //         guide_id: guideId,
        //         success: () => {},
        //         fail: () => {}
        //     });
        // }
    }

    /**
     * 设置视频自动化次数
     */
    static shezhi_shipin_zidonghua_cishu() {
        this.video_automatic_times = AL_Config_Manager.default.Instance.VideoAutomaticTimes;
        this.isReShow = false;
        this.log("重新拉起视频次数：", this.video_automatic_times);
    }

    /**
     * 重置视频自动化控制器
     */
    static ResetVideoAutomaticController() {
        this.video_automatic_times = 0;
        this.isReShow = false;
    }

    /**
     * 执行分享或视频任务
     * @param {string} location 位置
     * @param {Function} onSuccess 成功回调
     * @param {Function} onFail 失败回调
     * @param {Function} onPreCallback 预回调
     * @param {Function} onComplete 完成回调
     */
    static zhixing_fenxiang_huo_shipin(location, onSuccess, onFail, onPreCallback, onComplete) {
        // if (AL_Game_Const.shifou_no_net_work) {
        //     this.log("rewardVideo");
        //     if (onPreCallback) onPreCallback();
        //     return void (onSuccess && onSuccess());
        // }

        this.shezhi_shipin_zidonghua_cishu();
        this.fenxiang_huo_shipin(location, onSuccess, onFail, onPreCallback, onComplete);
    }

    /**
     * 执行分享或视频
     * @param {string} location 位置
     * @param {Function} onSuccess 成功回调
     * @param {Function} onFail 失败回调
     * @param {Function} onPreCallback 预回调
     * @param {Function} onComplete 完成回调
     */
    static fenxiang_huo_shipin(location, onSuccess, onFail, onPreCallback, onComplete) {
        // if (onSuccess) onSuccess();
        // return;
        if (this.currentLoc !== location) {
            this.currentLoc = location;
            this.videoFaultCount = 0;
        }
        this.log("-------video loc:", location);
        console.log("video_automatic_times", this.video_automatic_times);

        MiniGameSdk.AdvertManager.instance.showVideo(
            AL_SDK_Utils.vidioId,
            (res, count) => {
                console.log("用户看的视频广告个数是:", count); //微信平台只有1个或0个，抖音平台就可能有很多个，开发者可根据个数奖励
                switch (res) {
                    case MiniGameSdk.EAdVideoResult.ACCEPT:
                        //'用户看完广告，可以奖励了'
                        cc.game.resume();
                        this.ResetVideoAutomaticController();
                        if (onSuccess) onSuccess();
                        AL_UI_Root.default.Instance.xianshi_toast_xiaoxi(res.tips);
                        AL_Sound_Manager.default.Instance.zanting_beijing_yinyue();
                        AL_Sound_Manager.default.Instance.huifu_beijing_yinyue();
                        break;
                    case MiniGameSdk.EAdVideoResult.REJECT:
                        //'用户拒绝掉了广告，不奖励'
                        MiniGameSdk.API.xianshi_toast_xiaoxi("亲，广告没看完呢");
                        //par2 && par2();
                        break;
                    case MiniGameSdk.EAdVideoResult.ERROR:
                        //'播放广告发生错误，不奖励'
                        MiniGameSdk.API.xianshi_toast_xiaoxi("亲，请稍后再试");
                        cc.game.resume();
                        const closeVideoAutomaticControlLoc = AL_Config_Manager.default.Instance.CloseVideoAutomaticControlLoc;

                        if (closeVideoAutomaticControlLoc && closeVideoAutomaticControlLoc.includes(location)) {
                            this.isReShow = true;
                        }

                        if (this.video_automatic_times > 0 && this.isReShow && !AL_Config_Manager.default.Instance.baocuo_xinxi) {
                            this.video_automatic_times -= 1;
                            setTimeout(() => {
                                this.fenxiang_huo_shipin(location, onSuccess, onFail);
                            }, 10);
                        } else {
                            if (error.extra) {
                                const { errCode } = error.extra;
                                if (![1004, 120002, 1003].includes(errCode)) {
                                    this.videoFaultCount += 1;
                                    if (this.videoFaultCount >= AL_Config_Manager.default.Instance.VideoAutomaticTimes) {
                                        this.videoFaultCount = 0;
                                        if (onComplete) onComplete();
                                    }
                                }
                            }
                            AL_UI_Root.default.Instance.xianshi_toast_xiaoxi(error.tips);
                            this.ResetVideoAutomaticController();
                            AL_Sound_Manager.default.Instance.zanting_beijing_yinyue();
                            AL_Sound_Manager.default.Instance.huifu_beijing_yinyue();
                            if (onFail) onFail();
                        }
                        break;
                    default:
                        break;
                }
            }
        );

        // cc.game.pause();
        // LWGSDK.showShareOrAdByLoc({
        //     loc: location,
        //     defaultChoice: 1,
        //     extra: {},
        //     preCallback: () => {
        //         console.log("广告播放前回调");
        //         if (onPreCallback) onPreCallback();
        //     },
        //     success: (res) => {
        //         cc.game.resume();
        //         this.ResetVideoAutomaticController();
        //         if (onSuccess) onSuccess();
        //         AL_UI_Root.default.Instance.xianshi_toast_xiaoxi(res.tips);
        //         AL_Sound_Manager.default.Instance.zanting_beijing_yinyue();
        //         AL_Sound_Manager.default.Instance.huifu_beijing_yinyue();
        //     },
        //     fail: (error) => {
        //         console.error("分享/视频异常", error);
        //         cc.game.resume();
        //         const closeVideoAutomaticControlLoc = AL_Config_Manager.default.Instance.CloseVideoAutomaticControlLoc;

        //         if (closeVideoAutomaticControlLoc && closeVideoAutomaticControlLoc.includes(location)) {
        //             this.isReShow = true;
        //         }

        //         if (this.video_automatic_times > 0 && this.isReShow && !AL_Config_Manager.default.Instance.baocuo_xinxi) {
        //             this.video_automatic_times -= 1;
        //             setTimeout(() => {
        //                 this.fenxiang_huo_shipin(location, onSuccess, onFail);
        //             }, 10);
        //         } else {
        //             if (error.extra) {
        //                 const { errCode } = error.extra;
        //                 if (![1004, 120002, 1003].includes(errCode)) {
        //                     this.videoFaultCount += 1;
        //                     if (this.videoFaultCount >= AL_Config_Manager.default.Instance.VideoAutomaticTimes) {
        //                         this.videoFaultCount = 0;
        //                         if (onComplete) onComplete();
        //                     }
        //                 }
        //             }
        //             AL_UI_Root.default.Instance.xianshi_toast_xiaoxi(error.tips);
        //             this.ResetVideoAutomaticController();
        //             AL_Sound_Manager.default.Instance.zanting_beijing_yinyue();
        //             AL_Sound_Manager.default.Instance.huifu_beijing_yinyue();
        //             if (onFail) onFail();
        //         }
        //     }
        // });
    }


    /**
     * 显示分享菜单
     * @param {string} location 位置标识
     * @param {Function} onSuccess 成功回调
     * @param {Function} onFail 失败回调
     * @param {string} channel 渠道
     */
    static xianshi_fenxiang_caidan(location, onSuccess, onFail, channel = "") {
        if (onSuccess) onSuccess();
        
        MiniGameSdk.API.shareAppToFriends("点点消除，开心大爆破", "", "https://mmocgame.qpic.cn/wechatgame/Ve3hgJjFJU30mu8CeSOOOrWFRTia3ZtTrW90YNzQjX46zflCYCCiao9DsXqwIaRIdh/0");
       
        // if (AL_Game_Const.shifou_no_net_work) {
        //     if (onSuccess) onSuccess();
        // } else {
        //     LWGSDK.xianshi_fenxiang_caidan({
        //         loc: location,
        //         channel,
        //         extra: {},
        //         callback: (res) => {
        //             console.log("res:", res);
        //             if (res && res.share_status != null && res.share_status !== 0) {
        //                 if (onSuccess) onSuccess();
        //             } else {
        //                 if (onFail) onFail();
        //             }
        //         }
        //     });
        // }
    }

    /**
     * 获取邀请记录
     * @param {Function} callback 回调函数
     */
    static huoqu_yaoqing_jilu(callback) {
        if (callback) {
            callback({
                items: [1, 1, 1]
            });
        }
        // if (AL_Game_Const.shifou_no_net_work) {
        // } else {
        //     LWGSDK.huoqu_yaoqing_jilu({
        //         page: 1,
        //         page_size: 50,
        //         success: (response) => {
        //             console.log("获取被邀请记录", response);
        //             if (response && response.items) {
        //                 callback(response);
        //             }
        //         },
        //         fail: (error) => {
        //             console.error("获取被邀请记录异常", error);
        //         }
        //     });
        // }
    }

    /**
     * 获取随机浮点数
     * @param {number} min 最小值
     * @param {number} max 最大值
     * @returns {number} 随机数
     */
    static huoqu_suiji_shu(min, max) {
        return Math.random() * (max - min) + min;
    }

    /**
     * 获取随机整数
     * @param {number} min 最小值
     * @param {number} max 最大值
     * @returns {number} 随机整数
     */
    static huoqu_suiji_zhengshu(min, max) {
        const minCeil = Math.ceil(min);
        const maxFloor = Math.floor(max);
        return Math.floor(Math.random() * (maxFloor - minCeil)) + minCeil;
    }

    /**
     * 获取录屏状态
     * @returns {boolean} 录屏状态
     */
    static huoqu_luping_zhuangtai() {
        return this._recing;
    }

    /**
     * 开始录屏
     */
    static kaishi_luping() {
        // console.log("················startRec··················");
        // if (!AL_Game_Const.shifou_no_net_work && !cc.sys.isBrowser && !this._recing) {
        //     this._recing = true;
        //     console.log("---开始录屏");
        //     try {
        //         LWGSDK.startGameRecorder({
        //             duration: 300,
        //             timeRange: [20, 0],
        //             success: (res) => {
        //                 console.log("完成录屏", res);
        //             },
        //             fail: (error) => {
        //                 console.error("录屏异常", error);
        //             }
        //         });
        //     } catch (error) {
        //         console.error(error);
        //     }
        //     this._share_time = Date.now();
        // }
    }


    /**
     * 结束录屏
     */
    static jiesu_luping() {
        // console.log("················endRec··················", this._recing);
        // if (!AL_Game_Const.shifou_no_net_work && !cc.sys.isBrowser && this._recing) {
        //     this._recing = false;
        //     LWGSDK.stopGameRecorder();
        //     const currentTime = Date.now();
        //     console.log("录屏时间====", currentTime - this._share_time);
        //     this._dur_share_time = currentTime - this._share_time;
        //     this._canShare = (currentTime - this._share_time >= 3000 && !this.show_share_once);
        //     console.log("canShare:", this.shifou_ke_fenxiang);
        // }
    }

    /**
     * 分享录屏视频
     * @param {string} location 位置标识
     * @param {Function} onSuccess 成功回调
     * @param {Function} onFail 失败回调
     */
    static fenxinag_luping_shipin(location, onSuccess, onFail) {
        // if (AL_Game_Const.shifou_no_net_work || cc.sys.isBrowser) {
        //     if (onSuccess) onSuccess();
        // } else {
        //     // if (AL_Config_Manager.default.Instance.baocuo_xinxi !== 0) {
        //     //     LWGSDK.xianshi_fenxiang_caidan({
        //     //         loc: location,
        //     //         channel: "video",
        //     //         callback: (response) => {
        //     //             console.log("分享录屏回调参数", response);
        //     //             if (response.share_status === 1 || response.fake_callback_status === 1) {
        //     //                 onSuccess();
        //     //                 console.log("录屏分享成功", response);
        //     //                 AL_UI_Root.default.Instance.xianshi_toast_xiaoxi(response.tips);
        //     //             } else {
        //     //                 if (!response.tips) {
        //     //                     if (this._dur_share_time < 3000) {
        //     //                         AL_UI_Root.default.Instance.xianshi_toast_xiaoxi("分享失败,录屏时长小于3s");
        //     //                         console.log("分享失败,录屏时长小于3s");
        //     //                     } else {
        //     //                         AL_UI_Root.default.default.Instance.xianshi_toast_xiaoxi("分享失败，请重试");
        //     //                         console.log("分享失败，请重试");
        //     //                     }
        //     //                 } else {
        //     //                     AL_UI_Root.default.Instance.xianshi_toast_xiaoxi(response.tips);
        //     //                     console.log("分享失败====", response.tips);
        //     //                     if (onFail) onFail();
        //     //                 }
        //     //             }
        //     //         }
        //     //     });
        //     // }
        // }
    }

    /**
     * 获取是否可以分享
     */
    static get shifou_ke_fenxiang() {
        return this._canShare;
    }

    /**
     * 发起请求
     * @param {string} url 请求 URL
     * @param {object} data 请求数据
     * @param {string} method 请求方法
     * @param {boolean} crypto 是否加密
     * @returns {Promise<any>} 请求结果
     */
    static faqi_qingqiu(url, data, method = "POST", crypto = true) {
        return new Promise((resolve) => {
            resolve(null);
            return
            // LWGSDK.request({
            //     method,
            //     url,
            //     data: data || {},
            //     crypto,
            //     success: (response) => {
            //         resolve(response);
            //     },
            //     fail: (error) => {
            //         console.error("失败回调", error);
            //         resolve(null);
            //     }
            // });
        });
    }


    /**
     * 格式化时间为分钟:秒格式
     * @param {number} seconds 秒数
     * @returns {string} 格式化后的时间字符串
     */
    static geshihua_shijian_fen_miao(seconds = 0) {
        const minutes = Math.floor(seconds / 60);
        const remainingSeconds = seconds % 60;
        const minuteStr = minutes < 10 ? `0${minutes}` : `${minutes}`;
        const secondStr = remainingSeconds < 10 ? `0${remainingSeconds}` : `${remainingSeconds}`;
        return `${minuteStr}:${secondStr}`;
    }

    /**
     * 格式化时间为小时:分钟:秒格式
     * @param {number} seconds 秒数
     * @returns {string} 格式化后的时间字符串
     */
    static geshihua_shijian_shi_fen_miao(seconds) {
        const hours = Math.floor(seconds / 3600);
        const minutes = Math.floor((seconds % 3600) / 60);
        const remainingSeconds = seconds % 60;
        const hourStr = hours > 0 ? `${hours < 10 ? `0${hours}` : hours}:` : "";
        const minuteStr = minutes < 10 ? `0${minutes}` : `${minutes}`;
        const secondStr = remainingSeconds < 10 ? `0${remainingSeconds}` : `${remainingSeconds}`;
        return `${hourStr}${minuteStr}:${secondStr}`;
    }

    /**
     * 格式化时间为中文时分秒格式
     * @param {number} seconds 秒数
     * @returns {string} 格式化后的时间字符串
     */
    static geshihua_shijian_zhongwen_shi_fen_miao(seconds) {
        const hours = Math.floor(seconds / 3600);
        seconds %= 3600;
        const minutes = Math.floor(seconds / 60);
        const remainingSeconds = seconds % 60;
        const minuteStr = minutes < 10 ? `0${minutes}` : `${minutes}`;
        const secondStr = remainingSeconds < 10 ? `0${remainingSeconds}` : `${remainingSeconds}`;

        if (hours > 0) {
            return `${hours}时${minuteStr}分${secondStr}秒`;
        } else if (minutes > 0) {
            return `${minuteStr}分${secondStr}秒`;
        } else {
            return `${secondStr}秒`;
        }
    }



    /**
     * 获取在线时间
     */
    static get zaixian_shijian() {
        if (this._onlineTime === 0) {
            this._onlineTime = Date.now() / 1000;
        }
        return this._onlineTime;
    }

    /**
     * 获取服务器时间
     * @returns {Promise<boolean>} 是否成功获取服务器时间
     */
    static async huoqu_fuwuqi_shijian() {
        console.log("-----获取服务器时间");
        return Date.now() / 1000;
        // if (AL_Game_Const.shifou_no_net_work) {
        //     return Date.now() / 1000;
        // } else {
        //     return new Promise((resolve) => {
        //         LWGSDK.huoqu_fuwuqi_shijian({
        //             success: (serverTime) => {
        //                 console.log("获取服务器时间", serverTime);
        //                 this._onlineTime = serverTime;
        //                 resolve(true);
        //             },
        //             fail: (error) => {
        //                 console.log("获取服务器时间失败", error);
        //                 this._onlineTime = Date.now() / 1000;
        //                 resolve(false);
        //             }
        //         });
        //     });
        // }
    }

    /**
     * 获取时间由服务器
     * @returns {Promise<Date>} 服务器时间或本地时间
     */
    static huoqu_shijian_by_fuwuqi() {
        return Promise.resolve(new Date());
        // console.log("-----获取服务器时间");
        // if (AL_Game_Const.shifou_no_net_work) {
        //     return Promise.resolve(new Date());
        // } else {
        //     return new Promise((resolve) => {
        //         LWGSDK.huoqu_fuwuqi_shijian({
        //             success: (serverTime) => {
        //                 console.log("获取服务器时间", serverTime);
        //                 resolve(new Date(serverTime * 1000));
        //             },
        //             fail: (error) => {
        //                 console.log("获取服务器时间失败", error);
        //                 resolve(new Date());
        //             }
        //         });
        //     });
        // }
    }

    /**
     * 获取本地时间
     * @returns {number} 当前本地时间的秒数
     */
    static huoqu_bendi_shijian() {
        return Date.now() / 1000;
    }

    /**
     * 触发短振动
     */
    static vibrateShort() {
        // if (AL_Game_Const.platform && AL_Game_Storage_Manager.default.Instance.vibrate) {
        //     wx.vibrateShort();
        // }
    }

    /**
     * 触发长振动
     */
    static vibrateLong() {
        // if (AL_Game_Const.platform && AL_Game_Storage_Manager.default.Instance.vibrate) {
        //     wx.vibrateLong();
        // }
    }

    /**
     * 打印日志信息到控制台
     * @param  {...any} args 需要打印的日志信息
     */
    static log(...args) {
        // if (this.webConsole && (AL_Game_Const.shifou_xianshi_kongzhitai || AL_Game_Const.shifou_no_net_work)) {
        //     console.log(...args);
        // }
    }

    /**
     * 打印错误信息到控制台
     * @param  {...any} args 需要打印的错误信息
     */
    static error(...args) {
        // if (AL_Game_Const.shifou_xianshi_kongzhitai || AL_Game_Const.shifou_no_net_work) {
        //     console.error(...args);
        // }
    }

    /**
     * 打印警告信息到控制台
     * @param  {...any} args 需要打印的警告信息
     */
    static warn(...args) {
        // if (this.webConsole && (AL_Game_Const.shifou_xianshi_kongzhitai || AL_Game_Const.shifou_no_net_work)) {
        //     console.warn(...args);
        // }
    }

    /**
     * 开始记录时间成本
     * @param {string} action 动作标识
     */
    static kaishi_jilu_shijian_chengben(action) {
        // try {
        //     LWGSDK.kaishi_jilu_shijian_chengben(action);
        // } catch (error) {}
    }

    /**
     * 结束记录时间成本
     * @param {string} action 动作标识
     * @param {number} result 结果标识
     */
    static jiesu_jilu_shijian_chengben(action, result = 0) {
        // try {
        //     LWGSDK.jiesu_jilu_shijian_chengben({
        //         action,
        //         result,
        //         success: () => {},
        //         fail: () => {}
        //     });
        // } catch (error) {}
    }

    /**
     * 获取头条用户信息
     * @param {Function} onSuccess 成功回调
     * @param {Function} onFail 失败回调
     */
    static huoqu_tt_yonghu_xinxi(onSuccess, onFail) {


        // if (!this.jiancha_pingtai()) {
        //     if (onFail) onFail();
        //     console.warn("平台校验不通过");
        //     return;
        // }

        // if (AL_Config_Manager.default.Instance.nick_name && AL_Config_Manager.default.Instance.avatar_url) {
        //     if (onSuccess) onSuccess();
        // } else {
        //     LWGSDK.huoqu_tt_yonghu_xinxi({
        //         success: (userInfo) => {
        //             console.log("tt获取授权用户信息成功:", userInfo);
        //             if (userInfo.nickname) {
        //                 AL_Config_Manager.default.Instance.nick_name = userInfo.nickname;
        //             }
        //             if (userInfo.avatar_url) {
        //                 AL_Config_Manager.default.Instance.avatar_url = userInfo.avatar_url;
        //             }
        //             if (onSuccess) onSuccess();
        //         },
        //         fail: (error) => {
        //             console.log("tt获取授权用户信息异常:", error);
        //             if (onFail) onFail();
        //         }
        //     });
        // }
    }

    /**
     * 校验平台
     * @param {string} platform 平台名称
     * @returns {boolean} 平台是否有效
     */
    static jiancha_pingtai(platform) {
        const platforms = ["wx", "qq", "tt", "qg"];
        let isValid = false;

        if (platform) {
            if (window[platform]) {
                isValid = platform !== "wx" || (window.tt, true);
            }
        } else {
            for (const plat of platforms) {
                if (window[plat]) {
                    isValid = true;
                    break;
                }
            }
        }
        return isValid;
    }

    /**
     * 保持屏幕常亮
     */
    static baochi_pingmu_changliang() {
        // if (AL_Game_Const.platform && AL_Game_Const.platform.setKeepScreenOn) {
        //     console.log("开启屏幕常亮");
        //     AL_Game_Const.platform.setKeepScreenOn({
        //         keepScreenOn: true,
        //         fail: () => {
        //             setTimeout(() => {
        //                 AL_Game_Const.platform.setKeepScreenOn({
        //                     keepScreenOn: true
        //                 });
        //             }, 500);
        //         }
        //     });
        // }
    }

    /**
     * 报告模块进入事件
     * @param {string} moduleName 模块名称
     * @param {Function} onSuccess 成功回调
     * @param {Function} onFail 失败回调
     */
    static shangbao_mokuai_jinru_shijian(moduleName, onSuccess = null, onFail = null) {
        // console.log("reportModule", "---Enter:", moduleName);
        // if (AL_Game_Const.shifou_no_net_work) {
        //     if (onSuccess) onSuccess();
        // } else {
        //     LWGSDK.shangbao_mokuai_jinru_shijian({
        //         module: moduleName,
        //         success: () => {
        //             if (onSuccess) onSuccess();
        //         },
        //         fail: () => {
        //             if (onFail) onFail();
        //         }
        //     });
        // }
    }

    /**
     * 报告模块动作事件
     * @param {string} moduleName 模块名称
     * @param {string} actionIndex 动作索引
     */
    static shangbao_mokuai_dongzuo(moduleName, actionIndex) {
        // console.log("reportModule", "---Action:", `${moduleName}:${actionIndex}`);
        // if (!AL_Game_Const.shifou_no_net_work) {
        //     LWGSDK.shangbao_mokuai_dongzuo({
        //         module: moduleName,
        //         index: actionIndex,
        //         modValue: 1,
        //         success: () => {},
        //         fail: () => {}
        //     });
        // }
    }

    /**
     * 报告模块退出事件
     * @param {string} moduleName 模块名称
     * @param {Function} onSuccess 成功回调
     * @param {Function} onFail 失败回调
     */
    static shangbao_mokuai_tuichu_shijian(moduleName, onSuccess = null, onFail = null) {
        // console.log("reportModule", "---Exit:", moduleName);
        // if (AL_Game_Const.shifou_no_net_work) {
        //     if (onSuccess) onSuccess();
        // } else {
        //     LWGSDK.shangbao_mokuai_tuichu_shijian({
        //         module: moduleName,
        //         success: () => {
        //             if (onSuccess) onSuccess();
        //         },
        //         fail: () => {
        //             if (onFail) onFail();
        //         }
        //     });
        // }
        
    }

}

exports.AL_SDK_Utils = AL_SDK_Utils;
